package hu.imind.phonecalc.client.dto;

import com.extjs.gxt.ui.client.data.BaseModel;


@SuppressWarnings("serial")
public class Contact extends BaseModel {
    public Contact() {
    }

    public Contact(String name, String phone1, String type) {
        set("name", name);
        setPhoneNumber("phone1", phone1);
        set("type", type);
    }

    // TODO this is not used here. the plan is to use List of phone numbers
    // and check how to use types in BaseModel
    /*
    private String name;
    private String phone1;
    private String phone2;
    private String phone3;
    private String phone4;
    private String phone5;
    private String type;
    */

    // TODO this might go to the API
    public static String formatPhoneNumber(String s) {
        s = s.replaceAll(" ", "");
        if (s.contains("+")) {
        } else if (s.indexOf("06") == 0) {
            s = "+36" + s.substring(2);
        } else if (s.length() == 7) {
            s = "+3620" + s;
        } else if (s.length() >= 8) {
            s = "+36" + s;
        }
        return s;
    }
    public void setPhoneNumber(String field, String value) {
        set(field, formatPhoneNumber(value));
    }
    public String getName() {
        return get("name");
    }
    public void setName(String name) {
        set("name", name);
    }
    public String getPhone1() {
        return get("phone1");
    }
    public void setPhone1(String phone1) {
        setPhoneNumber("phone1", phone1);
    }
    public String getPhone2() {
        return get("phone2");
    }
    public void setPhone2(String phone2) {
        setPhoneNumber("phone2", phone2);
    }
    public String getPhone3() {
        return get("phone3");
    }
    public void setPhone3(String phone3) {
        setPhoneNumber("phone3", phone3);
    }
    public String getPhone4() {
        return get("phone4");
    }
    public void setPhone4(String phone4) {
        setPhoneNumber("phone4", phone4);
    }
    public String getPhone5() {
        return get("phone5");
    }
    public void setPhone5(String phone5) {
        setPhoneNumber("phone5", phone5);
    }
    public String getType() {
        return get("type");
    }
    public void setType(String type) {
        set("type", type);
    }
}
